<style lang="less">
@import "./login.less";
</style>

<template>
  <div class="login">
     <p style="color: #fff;font-size: 45px;text-align: center;padding-top:80px;">
				新疆奎木星红枣全产业链系统服务平台
			</p>
    <div class="login-con">
      
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">请输入正确的用户名和密码</p>
        </div>
      </Card>
    </div>
    <div
		style="color: #ffffff;position:absolute;bottom:28px;width:100%; font-size: 20px;text-align: center;">
		 红枣全产业链系统服务平台1.0版本
	</div>
    	<div
		style="padding-top: 20px;color: #ffffff;position:absolute;bottom:10px;width:100%; font-size: 13px;text-align: center;">
		推荐：IE8以上、Google等浏览器访问
	</div>	
  </div>
</template>

<script>
import LoginForm from "_c/login-form";
import { login } from "@/api/user";
import { setToken,sessionSave,getToken } from "@/libs/util";
import Cookies from "js-cookie";
import { Message } from "iview";
export default {
  components: {
    LoginForm
  },
  methods: {
    handleSubmit({ userName, userPassword }) {
      login({ userName, userPassword })
        .then(res => {
          console.log(res,11111)
          if (res.Token === "failure") {
            setToken(userName, "");
            Cookies.set("access", "");
            Cookies.set("userId", "");
            Cookies.set("RealName", "");
            Message.error("账号或密码错误");
            //不支持心语法
          } else if (res.Data.Token) {
            sessionSave("timeout",res.expires)
            let {UserName,Id,Token} = res.Data
            setToken(userName, UserName);
            setToken(Token)
            Cookies.set("access", "super_admin"); //这个我猜不到
            Cookies.set("userId", Id);
            Cookies.set("RealName", res.RealName);
            Cookies.set("userName", UserName);
        
            this.$router.push({
              path: "home"
            });
          }
        })
        .catch(err => {
          Message.error("账号或密码错误")
          console.log(err);
        });
    },
     mounted(){
	localStorage.clear();
  }
  }
};
</script>

<style>
</style>
